from norms import *
import matplotlib.pyplot as plt
from numpy import log


def func(x):
    return x ** 2 * log(2 + x)


def err(f):
    return lambda x: f(x) - func(x)


def display(f):
    print(norm1(err(f)))
    print(norm2(err(f)))
    print(norm_inf(err(f)))
    x0 = arange(-1, 1, 2 ** (-16))
    plt.plot(x0, f(x0), 'r', x0, func(x0))
    plt.savefig(str(f.__name__) + ".pdf")
    plt.show()
    plt.plot(x0, err(f)(x0), 'r')
    plt.savefig(str(f.__name__) + "_err.pdf")
    plt.show()


def display_all(f1, f2, f3):
    x0 = arange(-1, 1, 2 ** (-16))
    plt.plot(x0, f1(x0), 'r', x0, f2(x0), 'g', x0, f3(x0), 'b', x0, func(x0))
    plt.savefig("all.pdf")
    plt.show()
    plt.plot(x0, err(f1)(x0), 'r', x0, err(f2)(x0), 'g', x0, err(f3)(x0), 'b')
    plt.savefig("all_err.pdf")
    plt.show()
